package de.ff7rl.core.gamestate.dungeon;

import java.awt.event.KeyEvent;

import de.ff7rl.core.gamestate.AbstractGameStateController;
import de.ff7rl.core.gamestate.GameState;
import de.ff7rl.core.map.DungeonMapPrintUtils;
import de.ff7rl.ui.TerminalData;

public class DungeonGameStateController extends AbstractGameStateController {

  private TerminalData beforeMainMenuTerminalData;

  @Override
  public void enter(final GameState thePreviousGameState, final Object... theArguments) {
    super.enter(thePreviousGameState);
    if (thePreviousGameState == GameState.MAIN_MENU) {
      game().getTerminal().restore(beforeMainMenuTerminalData);
    } else {
      DungeonMapPrintUtils.printMap(game().getMap(), game().getTerminal());
    }
  }

  @Override
  public boolean input(final int theKeyCode) {
    if (theKeyCode == KeyEvent.VK_ESCAPE) {
      beforeMainMenuTerminalData = game().getTerminal().store();
      game().newGameState(GameState.MAIN_MENU);
      return true;
    }
    switch (theKeyCode) {
    case KeyEvent.VK_UP :
      // game().getMap().move(Direction.UP);
      DungeonMapPrintUtils.printMap(game().getMap(), game().getTerminal());
      return true;
    case KeyEvent.VK_DOWN :
      // game().getMap().move(Direction.DOWN);
      DungeonMapPrintUtils.printMap(game().getMap(), game().getTerminal());
      return true;
    case KeyEvent.VK_RIGHT :
      // game().getMap().move(Direction.RIGHT);
      DungeonMapPrintUtils.printMap(game().getMap(), game().getTerminal());
      return true;
    case KeyEvent.VK_LEFT :
      // game().getMap().move(Direction.LEFT);
      DungeonMapPrintUtils.printMap(game().getMap(), game().getTerminal());
      return true;
    }
    return false;
  }

}
